package morphage.gui;

import java.awt.Dimension;
import java.util.Iterator;
import java.util.Vector;

import javax.swing.JPanel;
import javax.swing.JList;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import morphage.engine.OperationLayer;
import morphage.engine.Pipeline;

public class PipelineTabPane extends JPanel implements ListSelectionListener
{
  public static final int ORIGINAL_IMAGE    = -1;
  public static final int RESULT_IMAGE      = -2;
	/**
   * 
   */
  private static final long serialVersionUID = 1L;

  public static final String     NAME    = "Pipeline";
	
	private JList          m_layersList;
	private static int     s_currentOperationId;
	
	public PipelineTabPane()
	{
	  
	  Vector<String> layersNames = new Vector<String>();
	  layersNames.add("Original");
	  Pipeline pipeline = Pipeline.getDefaultPipeline();
	  Iterator<OperationLayer> it = pipeline.getOperationLayers().iterator();
	  while( it.hasNext() )
	    layersNames.add( it.next().getName() );
	  layersNames.add("Result");
	  m_layersList = new JList( layersNames );
	  m_layersList.addListSelectionListener( this );
	  m_layersList.setPreferredSize( new Dimension(180, 100) );
	  m_layersList.setSelectedIndex( layersNames.size()-1 );
	  add( m_layersList );
	  
	  s_currentOperationId = -2;
	}

  @Override
  public void valueChanged(ListSelectionEvent e)
  {
    int nbOperationLayers = Pipeline.getDefaultPipeline().getOperationLayers().size();
    if( e.getFirstIndex() == 0 )
      s_currentOperationId = ORIGINAL_IMAGE;
    else if( e.getFirstIndex() > nbOperationLayers )
      s_currentOperationId = RESULT_IMAGE;
    s_currentOperationId = e.getFirstIndex()-1;
  }
  public static int getCurrentOperationId() { return s_currentOperationId; }
}
